import groovy.jmx.builder.modelmbean.ModelMBeanCollector

class ModelMBeanCollectorTest extends GroovyTestCase {
    def dataGenerator
    def collector

    void setUp() {
        dataGenerator = new NodeDataGenerator()
        collector = new ModelMBeanCollector()
    }

    void testCollectMbeanInfoFromNodeData() {
        def treeNode = dataGenerator.generateMBeanNodeData()
        assert treeNode != null

        def info = collector.collectMBeanInfo(treeNode)
        assert info != null
        assert info.getConstructor("ExposedTestBean") != null

        assert info.getAttribute("Color") != null
        assert info.getAttribute("Shape") != null
        assert info.getAttribute("Length") != null
        assert info.getAttribute("AccessPort") != null

        assert info.getOperation("stretch") != null
    }

    void testCollectMbeanInfoFromInstance() {
        def instance = new ExposedTestBean()
        def info = collector.collectMBeanInfo(instance)
        assert info != null

        assert info.getConstructor("ExposedTestBean") != null

        assert info.getAttribute("Id") != null
        assert info.getAttribute("Color") != null
        assert info.getAttribute("Shape") != null
        assert info.getAttribute("Length") != null
        assert info.getAttribute("AccessPort") != null

        assert info.getOperation("toss") != null
        assert info.getOperation("stretch") != null
        assert info.getOperation("receive") != null
    }

    void testCollectMBeanInfoFromJavaInstance() {
        def instance = new TestJavaBean()
        def info = collector.collectMBeanInfo(instance)
        assert info != null

        assert info.getConstructor("TestJavaBean") != null

        assert info.getAttribute("StringProperty") != null
        assert info.getAttribute("BoolProperty") != null
        assert info.getAttribute("IntProperty") != null

        assert info.getOperation("create") != null
        assert info.getOperation("destroy") != null
    }

}